home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n3.zip / BUILD.C next >
Text File  |  1990-01-31  |  7KB  |  188 lines

  1. /*********************  BUILD.C --  LISTING 2  **********************
  2. *  Build the translation tables for COMPRESS.ASM.
  3. *
  4. *  Author : Bob Zigon
  5. *  Date   : June 9, 1988
  6. *
  7. *  Compiler: Turbo C 2.0, MSC 5.1
  8. *  Memory model: any
  9. *  Compile switches: none
  10. *
  11. ********************************************************************/
  12.  
  13. #include <stdio.h>
  14.  
  15. #define TABLEWIDTH 8
  16.  
  17. /* The following table defines the mapping function in the compressed
  18.    file.  Each of the 256 possible ASCII characters is represented. If
  19.    the value is zero, then that character cannot be compressed and will
  20.    be unpacked as a space. The characters that one wants to be able to
  21.    compress and uncompress should be given numbers between 1 and 39. To
  22.    take a case in point, 'A' is ASCII 65 and is mapped to 0x01. Its
  23.    lower case counterpart, 'a' is ASCII 95, and it too is mapped to 0x01.
  24.  */
  25.  
  26. unsigned short int AsciiTable[256] = {
  27.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /*   0 -   7 */
  28.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /*   8 -  15 */
  29.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /*  16 -  23 */
  30.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /*  24 -  31 */
  31.       0x00, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00,   /*  32 -  39 */
  32.       0x00, 0x00, 0x00, 0x00, 0x26, 0x00, 0x25, 0x00,   /*  40 -  47 */
  33.       0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,   /*  48 -  55 */
  34.       0x23, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /*  56 -  63 */
  35.       0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,   /*  64 -  71 */
  36.       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,   /*  72 -  79 */
  37.       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,   /*  80 -  87 */
  38.       0x18, 0x19, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00,   /*  88 -  95 */
  39.       0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,   /*  96 - 103 */
  40.       0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,   /* 104 - 111 */
  41.       0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,   /* 112 - 119 */
  42.       0x18, 0x19, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 120 - 127 */
  43.  
  44.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 128 - 135 */
  45.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 136 - 143 */
  46.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 144 - 151 */
  47.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 152 - 159 */
  48.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 160 - 167 */
  49.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 168 - 175 */
  50.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 176 - 183 */
  51.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 184 - 191 */
  52.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 192 - 199 */
  53.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 200 - 207 */
  54.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 208 - 215 */
  55.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 216 - 223 */
  56.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 224 - 231 */
  57.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 232 - 239 */
  58.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   /* 240 - 247 */
  59.       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00    /* 248 - 255 */
  60.    };
  61.  
  62. FILE *fp;
  63.  
  64. /********************************************************************
  65. *                    Function Prototypes
  66. ********************************************************************/
  67.  
  68. void BuildXlateTable(char *, unsigned short int *, unsigned short int);
  69. void CheckTable(char *, unsigned short int *);
  70.  
  71. void main()
  72. {
  73.  
  74.     fp = fopen("COMPRESS.TBL", "w");
  75.  
  76.     fprintf(fp, "\n;");
  77.     fprintf(fp, "\n; Translation tables for Pack3 routine.");
  78.     fprintf(fp, "\n;\n");
  79.  
  80.     BuildXlateTable("Xlate0", AsciiTable, 1);
  81.     BuildXlateTable("Xlate1", AsciiTable, 40);
  82.     BuildXlateTable("Xlate2", AsciiTable, 1600);
  83.  
  84.     fprintf(fp, "\n;");
  85.     fprintf(fp, "\n; Translation table for UnPack3 routine.");
  86.     fprintf(fp, "\n;\n");
  87.  
  88.     CheckTable("ToAscii", AsciiTable);
  89.  
  90.     fputc('\n', fp);
  91.     fputc(0x1A, fp);
  92.     fclose(fp);
  93. }
  94.  
  95. void CheckTable(char *TableName, unsigned short int Table[])
  96. {
  97.     unsigned MinVal = 0xFFFF, MaxVal = 0;
  98.     short int i, ValCount, AscMatch;
  99.  
  100.     for (i = 0; i < 256; i++) 
  101.     {
  102.         if (Table[i] < MinVal) MinVal = Table[i];
  103.         if (Table[i] > MaxVal) MaxVal = Table[i];
  104.     }
  105.  
  106.     printf("\nAnalysis of Ascii Mappings");
  107.     printf("\n--------------------------\n");
  108.     printf("\nMinimum Value : %4d", MinVal);
  109.     printf("\nMaximum Value : %4d\n", MaxVal);
  110.  
  111.     printf("\nTranslated    Ascii");
  112.     printf("\n  Value       Value");
  113.     printf("\n-------------------");
  114.  
  115.     fprintf(fp, "%-10s", TableName);
  116.  
  117.     for ( ; MinVal <= MaxVal; MinVal++) 
  118.     {
  119.         /* Format and Output the Translated Value. */
  120.  
  121.         ValCount = AscMatch = 0;
  122.         printf("\n%3d          ", MinVal);
  123.  
  124.         /* Now search every entry in TABLE[] for a match against
  125.            the current Translated Value.  */
  126.  
  127.         for (i = 0; i < 256; i++)
  128.             if (Table[i] == MinVal) 
  129.             {
  130.                 if (AscMatch == 0) 
  131.                 {
  132.                     /* The Encoding for 0 is special;
  133.                        I have assigned a space to it. */
  134.  
  135.                     if (MinVal == 0)
  136.                         fprintf(fp,"dw %04Xh   ; %3d\n          ", 32, MinVal);
  137.                     else
  138.                         fprintf(fp,"dw %04Xh   ; %3d\n          ", i, MinVal);
  139.                     AscMatch = 1;
  140.                 }
  141.  
  142.                 if (++ValCount > 1 && ValCount != 12)
  143.                     printf(", ");
  144.                 else
  145.                 if (ValCount == 12) 
  146.                 {
  147.                    printf("\n             ");
  148.                    ValCount = 1;
  149.                 }
  150.                 printf("%3d", i);
  151.             }
  152.     }
  153.     printf("\n\n");
  154. }
  155.  
  156. void BuildXlateTable(char *TableName,
  157.                      unsigned short int Table[],
  158.                      unsigned short int Scale)
  159. {
  160.     short int i, j;
  161.  
  162.     /*  Output the Table Name.  */
  163.  
  164.     fprintf(fp, "\n%-10s", TableName);
  165.  
  166.     /*  Loop over every character in the input table. */
  167.  
  168.     for (i = 0; i < 256/TABLEWIDTH; i++) 
  169.     {
  170.         if (i)
  171.             fprintf(fp, "          ");
  172.  
  173.         for (j = 0; j < TABLEWIDTH; j++) 
  174.         {
  175.             if (j == 0)
  176.                 fprintf(fp, "dw ");
  177.             fprintf(fp, "%05Xh", Table[i*TABLEWIDTH+j]*Scale);
  178.  
  179.             /* Append a comma after every table entry 
  180.                except the last one on each row.  */
  181.  
  182.             if (j != TABLEWIDTH-1)
  183.                 fprintf(fp, ", ");
  184.         }
  185.         fprintf(fp, "\n");
  186.     }
  187. }
  188.